home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 May: Tool Chest / Developer CD Series Tool Chest (Apple Computer)(May 1999).iso / Tool Chest / Development Kits / C++ Related / THooks / TestHooks.cp < prev    next >
Encoding:
Text File  |  1990-09-14  |  1.1 KB  |  59 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        TestHooks.cp
  3.  
  4.     Contains:    MPW tool which demonstrates how to use the Hooks class.
  5.  
  6.     Written by:    Jack Palevich
  7.  
  8.     Copyright:    © 1990 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History:
  11.  
  12.         2/18/90        JHP        new today
  13.  
  14.     To Do:
  15. */
  16.  
  17. #include <Stdio.h>
  18. #include <Resources.h>
  19. #include <Traps.h>
  20. #include <CursorCtl.h>
  21.  
  22. #include "Hooks.h"
  23.  
  24. pascal void HandleCursorTrap(short /* trap */, THookStackFrame* /* args */, void* userRefNum)
  25.     {
  26.     long* countPtr = (long*) userRefNum;
  27.     
  28.     (*countPtr)++;
  29.  
  30.     }
  31.  
  32. int main()
  33.     {
  34.     long trapCount = 0;
  35.     const short kSpinCount = 10000;
  36.  
  37.     printf("Installing hooks\n"); fflush(stdout);
  38.  
  39.     static const short kOurHookTraps[1] = { _SetCursor };
  40.     THooks* cursorHook = new THooks(1, kOurHookTraps, HandleCursorTrap, &trapCount);
  41.  
  42.     printf("Calling SpinCursor %d times\n", kSpinCount); fflush(stdout);
  43.     
  44.     InitCursorCtl(nil);
  45.     
  46.     for ( short i = 0; i < kSpinCount; i++ )
  47.         {
  48.         SpinCursor(1);
  49.         }
  50.  
  51.     printf("SetCursor was called %d times\n", trapCount);
  52.  
  53.     printf("Removing hooks\n"); fflush(stdout);
  54.     delete cursorHook;
  55.  
  56.     printf("Exiting\n"); fflush(stdout);
  57.     return 0;
  58.     }
  59.